package com.yf.catcafe.mapper;

import com.yf.catcafe.pojo.dto.UserInfoDto;
import com.yf.catcafe.pojo.dto.UserRegisterDto;
import com.yf.catcafe.pojo.enity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from tb_user where username=#{username} and role=#{role}")
    User getByUsernameandRole(@Param("username") String username, @Param("role") String role);

    @Select("select * from tb_user where username=#{username}")
    User get(String username);

    @Select("select * from tb_user where id=#{id}")
    User getById(Long id);

    @Update("update tb_user set phone=#{phone},image=#{image},nick_name=#{nickname} where username=#{username}")
    void update(UserInfoDto userInfoDto);

    @Insert("insert into tb_user (username,password,role) values (#{username},#{password},#{role})")
    void register(UserRegisterDto userRegisterDto);
}
